package com.kuanter.kuanterauto.adapter;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.kuanter.kuanterauto.R;
import com.kuanter.kuanterauto.entity.AccountInfoNew;
import com.kuanter.kuanterauto.entity.CardInfo;

public class OtherAccountJinEAdapter extends BaseAdapter {
	private Context context;
	private TextView account_number;
	private TextView account_yu_e;
	private List<AccountInfoNew> accountInfoNewList;
	private TextView consumptionStyle;
	
	public OtherAccountJinEAdapter(Context context,List<AccountInfoNew> accountInfoNewList) {
		super();
		this.context = context;
		this.accountInfoNewList = accountInfoNewList;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return accountInfoNewList.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return accountInfoNewList.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int position, View contentView, ViewGroup arg2) {
		// TODO Auto-generated method stub
		View view = null;
		if(	contentView == null){
			view = View.inflate(context, R.layout.account_jine_list_item, null);
		}else {
			view = contentView;
		}
		
		account_number = (TextView)view.findViewById(R.id.account_number);
		account_yu_e = (TextView)view.findViewById(R.id.account_yu_e);
		consumptionStyle = (TextView)view.findViewById(R.id.consumptionStyle);
		
		account_number.setText(accountInfoNewList.get(position).getCardNumber());
		if("次数".equals(accountInfoNewList.get(position).getUnit())){
			account_yu_e.setText((int)Float.parseFloat(accountInfoNewList.get(position).getNumber())+accountInfoNewList.get(position).getUnit());
		}else if("积分".equals(accountInfoNewList.get(position).getUnit())){
			account_yu_e.setText(accountInfoNewList.get(position).getNumber()+accountInfoNewList.get(position).getUnit());
		}
		consumptionStyle.setText(accountInfoNewList.get(position).getConsumptionStyle());
		if(accountInfoNewList.size() >1){
			if(position == 0){
				RelativeLayout rl_account_list_item = (RelativeLayout) view.findViewById(R.id.rl_account_list_item);
				rl_account_list_item.setBackgroundResource(R.drawable.item_top_white_shape);
			}
			if(position == accountInfoNewList.size()-1){
				RelativeLayout rl_account_list_item = (RelativeLayout) view.findViewById(R.id.rl_account_list_item);
				rl_account_list_item.setBackgroundResource(R.drawable.item_white_bottom_shape);
			}
		}else if(accountInfoNewList.size() ==1){
			RelativeLayout rl_account_list_item = (RelativeLayout) view.findViewById(R.id.rl_account_list_item);
			rl_account_list_item.setBackgroundResource(R.drawable.topyuanjiao);
		}
		return view;
	}

}
